package control.Utils;

import java.nio.FloatBuffer;

import javax.media.opengl.GL;

import com.sun.opengl.util.BufferUtil;

public class DisplayUtils {
	public static void setMaterialColor(GL gl, float[] materialColor, int shininess) {
		gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
			
		float[] ambientbulb =  materialColor;
		float[] diffuseColor = materialColor;
		float[] specularColor =  {0,0,0,1f};
	
		FloatBuffer ambientBuffer = BufferUtil
				.newFloatBuffer(4);
		FloatBuffer diffuseBuffer = BufferUtil
				.newFloatBuffer(4);
		FloatBuffer specularBuffer = BufferUtil
				.newFloatBuffer(4);
		ambientBuffer.put(ambientbulb);
		ambientBuffer.rewind();
		diffuseBuffer.put(diffuseColor);
		diffuseBuffer.rewind();
		specularBuffer.put(specularColor);
		specularBuffer.rewind();
		gl.glColor4fv(diffuseBuffer);
		gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, ambientBuffer);
		gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, diffuseBuffer);
		gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, specularBuffer);
		gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, shininess);
		if(shininess > 100) {
			gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, diffuseBuffer);
		}
	}
}
